/**
 * 校园二手交易平台 - 搜索Mock数据
 * 提供搜索相关的模拟数据
 */

import { Product, ProductCategory, ProductCondition, ProductImage, ProductStatus, TransactionMethod } from '../types/product';
import { SearchHistory } from '../types/search';

/**
 * 生成模拟商品数据
 */
export const generateMockProducts = (count: number): Product[] => {
  const products: Product[] = [];
  
  const categories = ['electronics', 'books', 'clothing', 'daily', 'sports'];
  const campuses = ['main', 'east', 'west'];
  const faculties = ['computer', 'electronics', 'mechanical', 'economics', 'management'];
  
  for (let i = 0; i < count; i++) {
    const category = categories[Math.floor(Math.random() * categories.length)];
    const campus = campuses[Math.floor(Math.random() * campuses.length)];
    const faculty = faculties[Math.floor(Math.random() * faculties.length)];
    
    products.push({
      id: `product_${i + 1}`,
      title: generateProductTitle(category, i),
      description: generateProductDescription(category),
      price: Math.floor(Math.random() * 5000) + 10,
      originalPrice: Math.floor(Math.random() * 8000) + 100,
      category: category as ProductCategory,
      condition: ['new', 'like_new', 'lightly_used', 'used'][Math.floor(Math.random() * 4)] as ProductCondition,
      images: [
        {
          id: `img_${i + 1}_1`,
          url: `https://picsum.photos/300/200?random=${i + 1}`,
          thumbnailUrl: `https://picsum.photos/150/100?random=${i + 1}`,
          isCover: true,
          description: '商品图片1',
          uploadedAt: new Date()
        },
        {
          id: `img_${i + 1}_2`,
          url: `https://picsum.photos/300/200?random=${i + 100}`,
          thumbnailUrl: `https://picsum.photos/150/100?random=${i + 100}`,
          isCover: false,
          description: '商品图片2',
          uploadedAt: new Date()
        }
      ] as ProductImage[],
      status: ['available', 'sold', 'off_shelf'][Math.floor(Math.random() * 3)] as ProductStatus,
      viewCount: Math.floor(Math.random() * 500),
      favoriteCount: Math.floor(Math.random() * 50),
      inquiryCount: Math.floor(Math.random() * 20),
      tags: generateProductTags(category),
      transactionMethod: ['face_to_face', 'delivery', 'both'][Math.floor(Math.random() * 3)] as TransactionMethod,
      location: {
        school: '某大学',
        campus,
        address: '校园内',
        longitude: 116.3 + Math.random() * 0.5,
        latitude: 39.9 + Math.random() * 0.3
      },
      publisher: {
        userId: `user_${Math.floor(Math.random() * 50)}`,
        username: `用户${Math.floor(Math.random() * 1000)}`,
        avatar: `https://i.pravatar.cc/150?img=${Math.floor(Math.random() * 70)}`,
        isStudentVerified: Math.random() > 0.3,
        school: '某大学',
        contactInfo: {
          phone: Math.random() > 0.7 ? `138${Math.floor(Math.random() * 100000000).toString().padStart(8, '0')}` : undefined,
          wechat: Math.random() > 0.5 ? `wx_用户${Math.floor(Math.random() * 1000)}` : undefined
        }
      },
      publishedAt: new Date(Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000),
      updatedAt: new Date(Date.now() - Math.random() * 7 * 24 * 60 * 60 * 1000),
    });
  }
  
  return products;
};

/**
 * 生成商品标题
 */
const generateProductTitle = (category: string, index: number): string => {
  const titles = {
    electronics: [
      '二手iPhone 13 128G', '华为MatePad 11平板', '小米笔记本Pro', 
      'AirPods Pro 2代', '索尼PS5游戏机', '佳能单反相机',
      '罗技机械键盘', '戴尔显示器27寸', 'iPad Air 5代'
    ],
    books: [
      '计算机组成原理教材', '考研英语词汇', '高等数学辅导书',
      'C++程序设计教程', '微观经济学原理', '电路分析基础',
      '数据结构与算法', '自动控制原理', '马克思主义基本原理'
    ],
    clothing: [
      'Nike运动鞋42码', '优衣库卫衣L码', 'Adidas运动裤',
      '李宁篮球鞋', 'Vans帆布鞋', '匡威经典款',
      '冬季羽绒服', '夏季短袖T恤', '春秋夹克外套'
    ],
    daily: [
      '保温杯不锈钢', '台灯学习用', '收纳箱大号',
      '电热水壶', '床上用品四件套', '瑜伽垫健身',
      '小风扇便携', '充电宝2万毫安', '桌面收纳架'
    ],
    sports: [
      '篮球标准7号', '羽毛球拍双支', '乒乓球拍套装',
      '足球训练用', '哑铃健身器材', '跳绳运动器材',
      '瑜伽球', '轮滑鞋', '网球拍'
    ]
  };
  
  const categoryTitles = titles[category as keyof typeof titles] || ['商品'];
  return categoryTitles[Math.floor(Math.random() * categoryTitles.length)];
};

/**
 * 生成商品描述
 */
const generateProductDescription = (category: string): string => {
  const descriptions = {
    electronics: '设备功能完好，外观有轻微使用痕迹，配件齐全，支持验货。',
    books: '教材保存完好，内有少量笔记，不影响使用，适合考研复习。',
    clothing: '衣服洗过几次，穿着舒适，尺码标准，适合学生日常穿着。',
    daily: '物品使用正常，保养良好，适合宿舍生活使用。',
    sports: '运动器材功能正常，适合健身锻炼，支持面交验货。'
  };
  
  return descriptions[category as keyof typeof descriptions] || '商品描述';
};

/**
 * 生成商品标签
 */
const generateProductTags = (category: string): string[] => {
  const tags = {
    electronics: ['苹果', '华为', '小米', '电子产品', '二手'],
    books: ['教材', '考研', '专业课', '学习资料', '二手书'],
    clothing: ['运动', '休闲', '学生款', '校园风', '二手服装'],
    daily: ['宿舍', '生活用品', '实用', '二手'],
    sports: ['运动', '健身', '器材', '校园体育']
  };
  
  return tags[category as keyof typeof tags] || ['二手'];
};

/**
 * 搜索建议数据
 */
export const mockSearchSuggestions = [
  '笔记本电脑', 'iPhone', '教材', '考研资料', '运动鞋',
  '耳机', '键盘', '显示器', '专业课书', '考研英语',
  '二手手机', '平板电脑', '教材书', '运动装备', '宿舍用品',
  '学习资料', '电子产品', '教材辅导', '考研政治', '数学书',
  '英语四六级', '计算机二级', '专业课教材', '二手教材', '校园交易'
];

/**
 * 搜索历史数据
 */
export const mockSearchHistory: SearchHistory[] = [
  {
    id: '1',
    keyword: '笔记本电脑',
    searchedAt: new Date(Date.now() - 2 * 60 * 60 * 1000),
    resultCount: 156,
    isFavorite: false
  },
  {
    id: '2',
    keyword: '考研英语',
    searchedAt: new Date(Date.now() - 24 * 60 * 60 * 1000),
    resultCount: 89,
    isFavorite: true
  },
  {
    id: '3',
    keyword: '运动鞋',
    searchedAt: new Date(Date.now() - 3 * 24 * 60 * 60 * 1000),
    resultCount: 67,
    isFavorite: false
  },
  {
    id: '4',
    keyword: '教材',
    searchedAt: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000),
    resultCount: 234,
    isFavorite: false
  }
];

/**
 * 热门搜索数据
 */
export const mockHotKeywords = [
  { keyword: '笔记本电脑', count: 1567 },
  { keyword: 'iPhone', count: 1289 },
  { keyword: '教材', count: 987 },
  { keyword: '考研资料', count: 856 },
  { keyword: '运动鞋', count: 723 },
  { keyword: '耳机', count: 689 },
  { keyword: '键盘', count: 567 },
  { keyword: '显示器', count: 489 },
  { keyword: '专业课书', count: 456 },
  { keyword: '考研英语', count: 423 }
];

/**
 * 分类推荐数据
 */
export const mockCategoryRecommendations = {
  electronics: [
    '笔记本电脑', '手机', '平板电脑', '耳机', '键盘',
    '显示器', '游戏机', '相机', '智能手表'
  ],
  books: [
    '教材', '考研资料', '专业课书', '英语四六级',
    '计算机二级', '考研政治', '数学书', '辅导书'
  ],
  clothing: [
    '运动鞋', '卫衣', '运动裤', 'T恤', '外套',
    '裤子', '鞋子', '羽绒服', '衬衫'
  ],
  daily: [
    '台灯', '保温杯', '收纳箱', '电热水壶',
    '床上用品', '瑜伽垫', '小风扇', '充电宝'
  ],
  sports: [
    '篮球', '羽毛球拍', '乒乓球拍', '足球',
    '哑铃', '跳绳', '瑜伽球', '轮滑鞋'
  ]
};

export default {
  generateMockProducts,
  mockSearchSuggestions,
  mockSearchHistory,
  mockHotKeywords,
  mockCategoryRecommendations
};